define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'order_appraise/index' + location.search,
                    add_url: '',
                    edit_url: '',
                    detail_url: 'order_appraise/edit',
                    del_url: '',
                    multi_url: 'order_appraise/multi',
                    import_url: 'order_appraise/import',
                    table: 'order_appraise',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'recycler_id', title: __('Recycler_id'), visible: false},
                        {field: 'order.order_no', title: __('Order.order_no'), operate: 'LIKE'},
                        {field: 'order.username', title: __('Order.username'), operate: 'LIKE'},
                        {field: 'order.recycler_name', title: __('Order.recycler_name'), operate: 'LIKE'},
                        {field: 'receiving_text', title: __('Receiving'), operate: false},
                        {field: 'come_text', title: __('Come'), operate: false},
                        {field: 'service_text', title: __('Service'), operate: false},
                        {field: 'evaluate', title: __('Evaluate'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            events: {
                                'click .btn-detail': function (e, value, row, index) {
                                    e.stopPropagation();
                                    e.preventDefault();
                                    var table = $(this).closest('table');
                                    var options = table.bootstrapTable('getOptions');
                                    var ids = row[options.pk];
                                    row = $.extend({}, row ? row : {}, {ids: ids});
                                    var url = Table.api.replaceurl(options.extend.detail_url, row, table);
                                    Fast.api.open(url, $(this).data("original-title") || $(this).attr("title") || __('Edit'), $(this).data() || {});
                                }
                            },
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('Detail'),
                                    title: __('Detail'),
                                    icon: '',
                                    classname: 'btn btn-xs btn-info btn-detail'
                                }
                            ],
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});